package cn.xej.health.team.controller;

import cn.xej.health.common.utils.CommonResult;
import cn.xej.health.team.service.CaptainService;
import cn.xej.health.team.vo.Member;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author xej
 */
@RefreshScope
@RestController
@RequestMapping("/captain")
public class CaptainController {

    @Autowired
    private CaptainService captainService;

    /**
     * 获取团队里的医生
     * @param uuid
     * @param pageIndex
     * @param pageSize
     * @param searchName
     * @return
     */
    @GetMapping("/list/{uuid}")
    public CommonResult list(@PathVariable("uuid")Integer uuid, @RequestParam("pageIndex")Integer pageIndex, @RequestParam("pageSize")Integer pageSize, @RequestParam("searchName")String searchName){
        return captainService.queryMemberList(uuid,pageIndex,pageSize,searchName);
    }

    /**
     * 删除团队里的医生
     * @param uuids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] uuids){
        List<Integer> uuidList = Arrays.asList(uuids);
        captainService.delete(uuidList);
        return CommonResult.success(null);
    }

    /**
     * 获取剩余的医生
     * @return
     */
    @GetMapping("/initRemainUserList")
    public CommonResult initRemainUserList(){
        return captainService.initRemainUserList();
    }

    /**
     * 添加医生到团队
     * @return
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody Member member){
        return captainService.add(member.getCaptainId(),member.getUuid());
    }


    @GetMapping("/getTeamDockerList/{tid}")
    public CommonResult getTeamDockerList(@PathVariable("tid")Integer tid,@RequestParam("pageIndex")Integer pageIndex,@RequestParam("pageSize")Integer pageSize){
        return captainService.getTeamDockerList(tid,pageIndex,pageSize);
    }

}
